<template>
  <div class="admin-login">
    <VueParticles :options="particlesOptions" />
    <div class="login-container">
      <div class="login-left">
        <div title="未设计" class="login-logo"></div>
        <img width="450" src="/src/assets/year2022.svg" alt="" />
      </div>
      <div class="login-right">
        <el-form :model="loginForm" :rules="loginRules" ref="loginFormRef" class="login-form">
          <h1 class="login-title">后管登录</h1>
          <div class="formItem">
            <el-form-item required prop="username">
              <el-input required name="username" class="login-input" prefix-icon="el-icon-user"
                v-model="loginForm.username" placeholder="用户名/邮箱" clearable />
            </el-form-item>

            <el-form-item required prop="password">
              <el-input required name="password" class="login-input" show-password prefix-icon="el-icon-lock"
                v-model="loginForm.password" placeholder="请输入密码" clearable />
            </el-form-item>

            <!-- <el-form-item class="form-captcha">
              <el-input placeholder="验证码" name="code" prefix-icon="el-icon-picture-filled" class="login-input"
                style="height: 44px; margin-right: 12px" type="text" v-model="loginForm.code" />
              <img style="width: 120px; height: 42px" :src="captchaSrc" alt="验证码" title="验证码" />
            </el-form-item> -->

            <el-form-item>
              <!--  <el-button @click.prevent="handleLogin" :loading="loading" class="login-btn" type="primary"
                size="large">登录 </el-button> -->
              <el-button @click.prevent="handleLogin" :loading="loading" class="login-btn" type="primary">登录</el-button>
            </el-form-item>
          </div>
        </el-form>
      </div>
      <!-- <div class="login-footer">Powered by 禾几元</div> -->
    </div>
  </div>
</template>


<script setup>
  import {
    ref,
    defineComponent
  } from 'vue'
  import {
    useLogin
  } from './useLogin'
  import backgrounds from "./loginBackgronds";
  const loading = ref(false)
  const loginFormRef = ref(null)
  const {
    loginForm,
    loginRules,
    code,
    loginPassed
  } = useLogin()
  const captchaSrc = `http://www.webxml.com.cn/WebServices/ValidateCodeWebService.asmx/cnValidateImage?byString=${code}`
  const randomBg = backgrounds[Math.floor(Math.random() * backgrounds.length)]
  const handleLogin = () => {
    loginFormRef.value.validate((valid) => {
      if (valid) {
        loading.value = true
        loginPassed().finally(() => (loading.value = false))
      }
    })
  }
  const handleClick = (tab, event) => {
    console.log(tab, event)
  }
</script>


<style lang="scss" scoped>
  $bg-input: #f1f2f3; // 输入框背景颜色
  $sm-width: 768px; // 小屏幕平板尺寸
  $input-height: 44px;

  .admin-login {
    position: relative;
    height: 100vh;
    padding: 0 1rem;
    overflow: hidden;
    background: #293146;

    &>.login-container {
      position: relative;
      display: flex;
      align-items: center;
      height: 100%;
      width: 900px;
      background: #fff;
      height: 400px;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
  }


  .login-left {
    width: 510px;
    height: 400px;
    user-select: none;
    background-size: 100%;
    background: #516396;

    .login-logo {
      font-size: 60px;
      letter-spacing: 12px;
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }

    // 暂无设计logo!
    .login-logo--deprecated {
      font-size: 60px;
      letter-spacing: 12px;
      background-image: v-bind('randomBg');
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }

  .login-right {
    display: flex;
    justify-content: flex-end;
    width: 384px;

    :deep(.form-captcha .el-form-item__content) {
      display: flex;
      justify-content: space-between;
      margin-bottom: 12px;
    }
  }

  .login-footer {
    position: absolute;
    bottom: 10px;
    font-size: 6px;
    color: transparent;
    user-select: none;
    background: linear-gradient(to left, #0250c5 0%, #d43f8d 100%);
    -webkit-background-clip: text;
  }

  // 表单主体样式！
  .login-form {
    position: relative;
    align-self: flex-start;
    width: 800px;
    height: 380px;
    padding: 20px 40px;
    overflow: hidden;
    background: white;
    // border-radius: 0.4rem;
    // box-shadow: 4px 10px 16px rgb(36 37 38 / 13%);

    &>.login-title {
      display: inline-block;
      height: 26px;
      margin: 8px;
      color: #333;
      text-align: center;
      width: 100%;
      // padding-bottom: 40px;
      vertical-align: middle;
      cursor: pointer;
      user-select: none;
      font-size: 24px;
      margin-bottom: 40px;
    }

    // 输入框样式
    .login-input {
      // height: $input-height;
      font-size: 14px;
      // line-height: $input-height;
      margin: 4px 0;

    }

    // 登录按钮 使用绝对定位让动画效果正常点
    .login-btn {
      width: 100%;
      max-width: 800px;
      font-size: 16px;
      font-weight: bold;
      letter-spacing: 16px;
      margin: 0 auto;
      margin-top: 40px;
      font-size: 14px;
      font-weight: 300;
      height: 36px;
      background: #409eff;
    }

    :deep(.el-form-item__content) {
      flex-wrap: nowrap;
    }
  }

  .formItem {
    width: 100%;
  }

  @media screen and (max-width: $sm-width) {
    .login-left {
      display: none;
    }

    .login-right {
      align-self: flex-start;
      justify-content: center;
      width: 100%;
    }

    .login-form {
      padding-right: 1rem;
      padding-left: 1rem;
    }
  }

  .login-background {
    //可设置背景图 铺满屏
    background: linear-gradient(-180deg, #dceaf2 0%, #ffffff 100%);
    width: 100%;
    height: 100%;
    position: absolute;
  }

  .login-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    /* 确保粒子效果在其他内容之后 */
  }
</style>